package com.hd.controller.activiti;

import com.hd.controller.base.BaseController;
import com.hd.dao.JdbcDao;
import com.hd.entity.activiti.TempStoageTask;
import com.hd.service.activiti.TempStoageTaskService;
import com.hd.util.JsonUtil;
import com.hd.util.result.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 暂存
 */
@RequestMapping("/process/tempStoageTask")
@Controller
public class TempStoageTaskController extends BaseController {
    @Autowired
    private TempStoageTaskService tempStoageTaskService;
    @Autowired
    protected JdbcDao jdbcDao;

    @RequestMapping("/tolist")
    public String toList(){
        return "jsp/activiti/task/temp_stoage_task";
    }

    @ResponseBody
    @RequestMapping("/dataGrid")
    public Object selectData(TempStoageTask tempStoageTask, Integer page, Integer rows){
        PageInfo info=new PageInfo(page,rows);
        Map<String,Object> condition=new HashMap<>();
        condition.put("userid",tempStoageTask.getUserid());
        info.setCondition(condition);
        tempStoageTaskService.selectDataGrid(info);
        return info;
    }

    /**
     * 直接删除暂存
     * @param  id [description]
     * @return    [description]
     */
    @ResponseBody
    @RequestMapping("/del")
    public Object del(String id){
       TempStoageTask tempStoageTask=tempStoageTaskService.get(id);
       System.out.println(JsonUtil.toJson(tempStoageTask));
       String sql="delete from "+tempStoageTask.getTableName()+" where id=:id";
       Map<String,Object>paramMap=new HashMap<String,Object>();
       paramMap.put("id",tempStoageTask.getObjId());
       this.jdbcDao.delete(sql,paramMap);
       tempStoageTaskService.delete(id);
        return renderSuccess("删除成功！");
    }

    
    /**
     * 提交删除暂存数据
     * @param  id [description]
     * @return    [description]
     */
    @ResponseBody
    @RequestMapping("/deleteById")
    public Object deleteById(String id){
         tempStoageTaskService.delete(id);
         return renderSuccess();
    }
}
